﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class home : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["customer"] != null)
        {
            Customer c = (Customer)Session["customer"];
            lblCustomer.Text = c.Name;
            lblLogout.Visible = true;
        }
        else
        {
            lblCustomer.Text = "";
            lblLogout.Visible = false;
        }
        
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {

        lbldatetime.Text = DateTime.Now.ToString();
        //bussiness bus = new bussiness();
        //List<SentEcard> lstSentEcard = bus.getAllSentEcard();
        //List<listEmail> lstListEmail = bus.getAllListEmail();
        //foreach (SentEcard se in lstSentEcard)
        //{
        //    int i = 0;
        //    i++;
        //    if (se.DateSent.Day == DateTime.Now.Day && se.DateSent.Month == DateTime.Now.Month && se.DateSent.Year == DateTime.Now.Year)
        //    {
        //        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
        //        smtpClient.EnableSsl = true;
        //        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        //        smtpClient.UseDefaultCredentials = true;
        //        smtpClient.Credentials = new NetworkCredential("vanthanh26041989@gmail.com", "vanthanh");
        //        MailMessage message = new MailMessage();
        //        //Message object must be disposed before deleting temp attachment files

        //        message.From = new MailAddress("vanthanh26041989@gmail.com", "tranthanh");
        //        message.Subject = "thanh sent for you 1 ecard happy birhday";
        //        message.Body = "hi tennguoinhan! ";
        //        message.IsBodyHtml = true;
        //        foreach (listEmail email in lstListEmail)
        //        {
        //            if (email.SentEcardId == se.SentEcardId)
        //            {
        //                message.To.Add(email.Email);
        //            }
        //        }
        //        try
        //        {
        //            smtpClient.Send(message);
        //        }
        //        catch (Exception ex) {
        //            Response.Write(ex.ToString());
        //        }
        //    }

        //}

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bussiness bus = new bussiness();

        if (bus.checkNull(txtUserName.Text) || bus.checkNull(txtPassword.Text))
        {
            lbleror.Text = "must is not null";
        }
        else
        {
            Customer c = bus.checkLogin(txtUserName.Text, txtPassword.Text);
            if (c != null)
            {
                Session["customer"] = c;
                lblCustomer.Text = c.Name;
                lblLogout.Visible = true;
            }
            else
            {
                lbleror.Text = "username or pass not valid";
            }
        }
        
     
    }
}
